<template>
  <view class="container">
    <u-picker v-model="show" mode="time" :mask-close-able="false" @confirm="birthdayChange"></u-picker>
    <!-- <u-calendar v-model="show" mode="date" @change="birthdayChange"></u-calendar> -->
    <view class="birthday-box" @click="show=true">
      <u-cell-group>
        <u-cell-item :title="birthday||'请选择生日'"></u-cell-item>
      </u-cell-group>
    </view>
    <button class="save-btn" type="primary" @click="saveUpdate">保存</button>
  </view>
</template>

<script>
  /**
   * 建议昵称不重复
   */
  export default {
    data() {
      return {
        birthday: '',
        show: false
      };
    },
    onLoad() {
      let vuex_user = this.vuex_user // 从vuex拿
      this.birthday = vuex_user.birthday
    },
    methods: {
      // 保存更改
      async saveUpdate() {
        uni.showLoading({
          title: '保存中',
          mask: true
        })
        try {
          let vuex_user = this.vuex_user
          vuex_user.birthday = this.birthday

          // let checkContent_res = await request({
          // 	url: '/wechat/msgSecCheck',
          // 	method: 'POST',
          // 	data: {
          // 		scene: 1, // 场景枚举值（1 资料；2 评论；3 论坛；4 社交日志）
          // 		content: this.birthday,
          // 		openid: vuex_user.openid_mp
          // 	}
          // })

          // if (checkContent_res.success) {
          // 	let suggest = checkContent_res.data.result.suggest
          // 	if (suggest !== 'pass') {
          // 		uni.hideLoading()
          // 		uni.showToast({
          // 			title: '文本违规',
          // 			icon: 'error'
          // 		})
          // 		return
          // 	}
          // }

          await uniCloud.callFunction({
            name: 'star-community-user',
            data: {
              flag: 2,
              data: {
                id: vuex_user.id,
                updateData: {
                  birthday: this.birthday
                }
              }
            }
          })
          this.$u.vuex('vuex_user', vuex_user)
          uni.navigateBack()
          uni.hideLoading()
        } catch (err) {
          console.log(err);
          uni.hideLoading()
          uni.showToast({
            title: '昵称已被占用',
            icon: 'none'
          })
        }
      },
      // 昵称填写能力回调
      birthdayChange(e) {
        // console.log(e);
        this.birthday = e.year + '-' + e.month + '-' + e.day
        // console.log(e);
      }
    }
  }
</script>

<style scoped lang="scss">
  .container {
    height: 100vh;
    padding: 20rpx;
    background-color: #eee;
  }

  .birthday-box {
    padding: 20rpx 30rpx;
    background-color: #fff;
    border-radius: 20rpx;
  }

  .save-btn {
    margin-top: 50rpx;
  }
</style>